package com.inspur.gs.sbssdl.sbwhgl.sbwhby.sbwhby.front.sbebfkcx_frm.voactions;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.bff.api.manager.context.QueryContext;
import com.inspur.edp.bff.spi.action.query.BeforeQueryAction;
import com.inspur.edp.cef.entity.condition.EntityFilter;
import com.inspur.edp.cef.entity.condition.FilterCondition;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.ArrayList;

public class beforeQueryVOAction extends BeforeQueryAction {

	public beforeQueryVOAction(QueryContext context){
		super(context);
	}
	@Override
	public void execute() {
		String devId = (String) this.getContext().getVariableData().getValue("devId");

		String tzid = "efd56b39-0e8d-4441-9fa1-2b019b6fd862";

		SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
		try {
			ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
			//设备台账的变更
			IStandardLcp lcp = iLcpFactory.createLcpByBEId(tzid);
			String sbbh = (String) lcp.retrieve(devId).getData().getValue("sbbh");

			EntityFilter filter = getQueryContext().getFilter();
			ArrayList<FilterCondition> filterList = new ArrayList<>(FilterCondition.builder()
					.andEqual("sbbh", sbbh)
					.build());
			filter.addFilterConditions(filterList);

		} finally {
			SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
		}
	}
}
